namespace ASPNET.Queries
{
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Diagnostics;
    using System.IO;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Configuration;
    using ASPNET.StarterKit.IssueTracker;

    public class QueryList : Page
    {
        [AccessedThroughProperty("btnaci")]
        private Button _btnaci;
        [AccessedThroughProperty("btnacr")]
        private Button _btnacr;
        [AccessedThroughProperty("btnDelete")]
        private Button _btnDelete;
        [AccessedThroughProperty("Btnexcel")]
        private Button _Btnexcel;
        [AccessedThroughProperty("btnPerformQuery")]
        private Button _btnPerformQuery;
        [AccessedThroughProperty("DataGridexcel")]
        private DataGrid _DataGridexcel;
        [AccessedThroughProperty("disacr")]
        private ACR _disacr;
        private object designerPlaceholderDeclaration;

        public QueryList()
        {
            base.Init += new EventHandler(this.Page_Init);
            base.Load += new EventHandler(this.Page_Load);
        }

        public void AddQuery(object s, EventArgs e)
        {
            this.Response.Redirect("QueryDetail.aspx");
        }

        public void BindQueries()
        {
        }

        private void btnaci_Click(object sender, EventArgs e)
        {
            this.Response.Redirect("QueryDetail.aspx");
            this.disacr.Visible = false;
        }

        private void btnacr_Click(object sender, EventArgs e)
        {
            this.disacr.Visible = true;
        }

        private void Btnexcel_Click(object sender, EventArgs e)
        {
            string ConnectionString = ConfigurationSettings.AppSettings["ConnectionString"];
            string CommandText = "select acrcode as ACR号码, legal_name as 英文名称,Business_Name as 英文简称,CHname as 中文名称,city as 城市,Provincename as 省份  from ACR_SAP order by acrcode desc";
            SqlConnection myConnection = new SqlConnection(ConnectionString);
            SqlDataAdapter myCommand = new SqlDataAdapter(CommandText, myConnection);
            DataSet ds = new DataSet();
            myCommand.Fill(ds);
            this.DataGridexcel.DataSource = ds;
            this.DataGridexcel.DataBind();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.Charset = "";
            this.EnableViewState = false;
            StringWriter tw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(tw);
            this.DataGridexcel.RenderControl(hw);
            this.Response.Write(tw.ToString());
            this.Response.End();
        }

        public void btnPerformQueryClick(object s, EventArgs e)
        {
            this.ExecuteQuery();
        }

        public void DeleteQuery(object s, EventArgs e)
        {
            this.BindQueries();
        }

        public void ExecuteQuery()
        {
            try
            {
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                ProjectData.ClearProjectError();
            }
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
        }

        public void IssuesRebind(object s, EventArgs e)
        {
            this.ExecuteQuery();
        }

        private void Page_Init(object sender, EventArgs e)
        {
            this.InitializeComponent();
        }

        private void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                this.BindQueries();
                if (this.User.IsInRole("Project Manager") | this.User.IsInRole("Administrator"))
                {
                    this.Btnexcel.Visible = true;
                }
                else
                {
                    this.Btnexcel.Visible = false;
                }
            }
        }

        public void ProjectSelectedIndexChanged(object s, EventArgs e)
        {
            this.BindQueries();
        }

        protected virtual Button btnaci
        {
            get
            {
                return this._btnaci;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._btnaci != null)
                {
                    this._btnaci.Click -= new EventHandler(this.btnaci_Click);
                }
                this._btnaci = value;
                if (this._btnaci != null)
                {
                    this._btnaci.Click += new EventHandler(this.btnaci_Click);
                }
            }
        }

        protected virtual Button btnacr
        {
            get
            {
                return this._btnacr;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._btnacr != null)
                {
                    this._btnacr.Click -= new EventHandler(this.btnacr_Click);
                }
                this._btnacr = value;
                if (this._btnacr != null)
                {
                    this._btnacr.Click += new EventHandler(this.btnacr_Click);
                }
            }
        }

        protected virtual Button btnDelete
        {
            get
            {
                return this._btnDelete;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._btnDelete != null)
                {
                    this._btnDelete.Click -= new EventHandler(this.DeleteQuery);
                }
                this._btnDelete = value;
                if (this._btnDelete != null)
                {
                    this._btnDelete.Click += new EventHandler(this.DeleteQuery);
                }
            }
        }

        protected virtual Button Btnexcel
        {
            get
            {
                return this._Btnexcel;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._Btnexcel != null)
                {
                    this._Btnexcel.Click -= new EventHandler(this.Btnexcel_Click);
                }
                this._Btnexcel = value;
                if (this._Btnexcel != null)
                {
                    this._Btnexcel.Click += new EventHandler(this.Btnexcel_Click);
                }
            }
        }

        protected virtual Button btnPerformQuery
        {
            get
            {
                return this._btnPerformQuery;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._btnPerformQuery != null)
                {
                    this._btnPerformQuery.Click -= new EventHandler(this.btnPerformQueryClick);
                }
                this._btnPerformQuery = value;
                if (this._btnPerformQuery != null)
                {
                    this._btnPerformQuery.Click += new EventHandler(this.btnPerformQueryClick);
                }
            }
        }

        protected virtual DataGrid DataGridexcel
        {
            get
            {
                return this._DataGridexcel;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._DataGridexcel != null)
                {
                }
                this._DataGridexcel = value;
                if (this._DataGridexcel != null)
                {
                }
            }
        }

        protected virtual ACR disacr
        {
            get
            {
                return this._disacr;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._disacr != null)
                {
                }
                this._disacr = value;
                if (this._disacr != null)
                {
                }
            }
        }
    }
}

